/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mailbox.Note.Rectangle;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateNote
/*     */   extends RedoableOp
/*     */ {
/*     */   private int mId;
/*     */   private int mFolderId;
/*     */   private String mContent;
/*     */   private long mColor;
/*     */   private Note.Rectangle mBounds;
/*     */   
/*     */   public CreateNote()
/*     */   {
/*  43 */     super(MailboxOperation.CreateNote);
/*  44 */     this.mId = 0;
/*  45 */     this.mFolderId = 0;
/*     */   }
/*     */   
/*     */   public CreateNote(int mailboxId, int folderId, String content, Color color, Note.Rectangle bounds)
/*     */   {
/*  50 */     this();
/*  51 */     setMailboxId(mailboxId);
/*  52 */     this.mId = 0;
/*  53 */     this.mFolderId = folderId;
/*  54 */     this.mContent = (content != null ? content : "");
/*  55 */     this.mColor = color.getValue();
/*  56 */     this.mBounds = bounds;
/*     */   }
/*     */   
/*     */   public int getNoteId() {
/*  60 */     return this.mId;
/*     */   }
/*     */   
/*     */   public void setNoteId(int id) {
/*  64 */     this.mId = id;
/*     */   }
/*     */   
/*     */   protected String getPrintableData() {
/*  68 */     StringBuffer sb = new StringBuffer("id=").append(this.mId);
/*  69 */     sb.append(", folder=").append(this.mFolderId);
/*  70 */     sb.append(", content=").append(this.mContent);
/*  71 */     sb.append(", color=").append(this.mColor);
/*  72 */     if (this.mBounds != null)
/*  73 */       sb.append(", bounds=(").append(this.mBounds).append(")");
/*  74 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException {
/*  78 */     out.writeInt(this.mId);
/*  79 */     out.writeInt(this.mFolderId);
/*  80 */     out.writeShort((short)-1);
/*  81 */     out.writeUTF(this.mContent);
/*     */     
/*  83 */     out.writeLong(this.mColor);
/*  84 */     out.writeInt(this.mBounds.x);
/*  85 */     out.writeInt(this.mBounds.y);
/*  86 */     out.writeInt(this.mBounds.width);
/*  87 */     out.writeInt(this.mBounds.height);
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException {
/*  91 */     this.mId = in.readInt();
/*  92 */     this.mFolderId = in.readInt();
/*  93 */     in.readShort();
/*  94 */     this.mContent = in.readUTF();
/*  95 */     if (getVersion().atLeast(1, 27)) {
/*  96 */       this.mColor = in.readLong();
/*     */     } else
/*  98 */       this.mColor = in.readByte();
/*  99 */     int x = in.readInt();
/* 100 */     int y = in.readInt();
/* 101 */     int w = in.readInt();
/* 102 */     int h = in.readInt();
/* 103 */     this.mBounds = new Note.Rectangle(x, y, w, h);
/*     */   }
/*     */   
/*     */   public void redo() throws Exception {
/* 107 */     int mboxId = getMailboxId();
/* 108 */     Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*     */     try
/*     */     {
/* 111 */       mailbox.createNote(getOperationContext(), this.mContent, this.mBounds, Color.fromMetadata(this.mColor), this.mFolderId);
/*     */     } catch (MailServiceException e) {
/* 113 */       String code = e.getCode();
/* 114 */       if (code.equals("mail.ALREADY_EXISTS")) {
/* 115 */         if (mLog.isInfoEnabled())
/* 116 */           mLog.info("Note " + this.mId + " already exists in mailbox " + mboxId);
/*     */       } else {
/* 118 */         throw e;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateNote.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */